﻿function baseMsg() {
	$("#baseMessage").show();
	$("#changePsw").hide();
	$("#accRel").hide();
	$("#accSafe").hide();
	document.getElementById("1").style.backgroundColor="#F1FACD";
	document.getElementById("2").style.backgroundColor="#F8F8F8";
	document.getElementById("3").style.backgroundColor="#F8F8F8";
	document.getElementById("4").style.backgroundColor="#F8F8F8";
}
function changePsw() {
	$("#baseMessage").hide();
	$("#changePsw").show();
	clearPassword();
	$("#accRel").hide();
	$("#accSafe").hide();
	document.getElementById("1").style.backgroundColor="#F8F8F8";
	document.getElementById("2").style.backgroundColor="#F1FADD";
	document.getElementById("3").style.backgroundColor="#F8F8F8";
	document.getElementById("4").style.backgroundColor="#F8F8F8";
}
function accRel() {
	$("#baseMessage").hide();
	$("#changePsw").hide();
	$("#accRel").show();
	$("#accSafe").hide();
	var d=document.getElementById("accRel");
	d.innerHTML="";
	$.getJSON("getUserRelatedThirdPartry.action",function(data){
		if(data.QQ==1){
			d.innerHTML+="<div style='float:left'><font>已关联QQ帐号</font></div><div style='float:right'><input type='button' value='解除关联' /></div>";
		}else{
			d.innerHTML+="<div style='float:left'><font>还未关联QQ帐号</font></div><div style='float:right'><input type='button' value='关联QQ' /></div>";
		}
	});
	document.getElementById("1").style.backgroundColor="#F8F8F8";
	document.getElementById("2").style.backgroundColor="#F8F8F8";
	document.getElementById("3").style.backgroundColor="#F1FAED";
	document.getElementById("4").style.backgroundColor="#F8F8F8";
}
function accSafe() {
	$("#baseMessage").hide();
	$("#changePsw").hide();
	$("#accRel").hide();
	$("#accSafe").show();
	document.getElementById("1").style.backgroundColor="#F8F8F8";
	document.getElementById("2").style.backgroundColor="#F8F8F8";
	document.getElementById("3").style.backgroundColor="#F8F8F8";
	document.getElementById("4").style.backgroundColor="#F1FAFD";
}
var c1=true;
function checkUser() {
	var user = document.getElementById("username").value;
	_user = document.getElementById("hiddenusername");
	if (user == "" || user == null) {
		alert("用户名不能为空");
		c1 = false;
	} else if (!/^(\w){2,15}$/.test(user)) {
		alert("用户名在2-15位之间");
		c1 = false;
	} else if (user != _user) {
		c1 = true;
		$.post("yanuser.action", {
			username : user
		}, function(data) {
			if (data.str == "false") {
				alert("此用户名已被注册");
				c1 = false;
			}
		}, "json");
	}
}
function checkSubmit() {
	if (c1) {
		document.getElementById("form1").submit();
	} else {
		alert("填写信息有错或者不完整");
	}
}
function checkMobile() {
	var tele = document.getElementById("telephone").value;
	if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(tele))) {
		$("#telephone").val("");
	}
}
function checkPhone() {
	var tele1 = document.getElementById("specialplane1").value;
	var tele2 = document.getElementById("specialplane2").value;
	if (!(/^\d{2,4}-\d{8}$/.test(tele1 + "-" + tele2))) {
		document.getElementById("specialplaneMsg").innerHTML = "×";
	}
}
var check1,check2,check3;
function checkOldPass() {
	var oldp=$("#oldpassword").val();
	if(oldp==null||oldp==""){
		alert("原密码不能为空");
		check1=false;
	}else{
		check1=true;
	}
}
function checkPass1() {
	var p1=$("#p1").val();
	if(p1==null||p1==""){
		alert("新密码不能为空");
		check2=false;
	}else{
		check2=true;
	}
}
function checkPass2() {
	var p2=$("#p2").val();
	if(p2==null||p2==""||p2!=$("#p1").val()){
		alert("密码输入不一致");
		check3=false;
	}else{
		check3=true;
	}
}
function clearPassword(){
	$("#oldpassword").val("");
	$("#p1").val("");
	$("#p2").val("");
}
function changePassword(){
	if(check1==true&&check2==true&&check3==true){
		$.getJSON("changPasswordAction.action",{
			oldpassword:$("#oldpassword").val(),
			password : $("#p2").val()
		},function(data) {
			if(data.result=="1"){
				alert("原密码输入错误");
			}else if(data.result=="2"){
				alert("密码修改成功");
			}
		});
	}else{
		alert("请填写完整");
	}
}